package com.xiaoxi.open.design.behavioral.chainofresponsibilitypattern.service.password;

import com.xiaoxi.open.design.behavioral.chainofresponsibilitypattern.domain.password.CheckResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @ClassName ConfirmPasswordCheck
 * @Description
 * @Author xiaoxi
 * @Date 2022/7/11 21:53
 * @Version 1.0
 */
@Component
public class ConfirmPasswordCheck extends AbstractCheckPassword {

    private String confirmPassword;

    public ConfirmPasswordCheck() {
    }

    public ConfirmPasswordCheck(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    @Override
    public void doHandler(String password, CheckResult checkResult) throws Exception {
        if (StringUtils.isNotBlank(confirmPassword)) {
            if (!password.equals(confirmPassword)) {
                checkResult.getErrorReason().add("密码不一致");
            }
        }
    }
}
